package m202401.d02;

import java.util.HashMap;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/1/2 09:37
 */
//1. 两数之和
public class Q1 {
    public int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{i, map.get(target - nums[i])};
            }
            map.put(nums[i], i);
        }
        return new int[0];
    }
}
